home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / mswin / netsort / netdump.c < prev   
Encoding:
C/C++ Source or Header  |  1992-02-02  |  2.9 KB  |  133 lines

  1. /* Code to sort Netrom node listing  */
  2. /* All code in NRCMD.C               */
  3. /* D. Crompton  2/92                 */
  4.                        
  5. /* Define the initial sort for netrom list dumps */
  6. /*  1=alias / 0=call                             */
  7. /* Add after includes in nrcmd.c                 */
  8.  
  9. unsigned Nr_sorttype=1;
  10.  
  11. /* Add to prototypes in nrcmd.c */
  12.  
  13. static int doroutesort __ARGS((int argc,char *argv[],void *p));
  14.     
  15. /* Add struct cmds in nrcmd.c    */        
  16. /* The sort command lines below  */        
  17.  
  18. static struct cmds Routecmds[] = {
  19.     "add",  dorouteadd,     0, 6,
  20.         "netrom route add <alias> <destination> <interface> <quality> <neighbor>",
  21.     "drop", doroutedrop, 0, 4,
  22.         "netrom route drop <destination> <neighbor> <interface>",
  23.     "info", dorouteinfo, 0, 2,
  24.         "netrom route info <destination>",
  25.     "sort", doroutesort, 0, 1,
  26.         "",
  27.     NULLCHAR,
  28. } ;
  29.  
  30.  
  31.  
  32.  
  33. /* Dump a list of known netrom routes in   */
  34. /* sorted order determined by sort         */
  35. /* flag - default = sort by alias          */
  36. /* Insert this funtion in place of current */
  37. /* function in nrcmd.c                     */
  38.  
  39. int
  40. doroutedump()
  41. {
  42.     extern unsigned Nr_sorttype;
  43.     register struct nrroute_tab *rp ;
  44.     register int i,j,k, column ;
  45.     char buf[17] ;
  46.     char *cp,*temp ;
  47.     
  48.     column = 1 ;
  49.     
  50.     for(i = 0,j=0 ; i < NRNUMCHAINS ; i++)
  51.         for(rp = Nrroute_tab[i] ; rp != NULLNRRTAB ;j++,rp = rp->next);
  52.     if (j) {
  53.     
  54.      temp = mallocw (j*17);
  55.     
  56.      for(i = 0,k=0 ; i < NRNUMCHAINS ; i++)
  57.         for(rp = Nrroute_tab[i] ; rp != NULLNRRTAB ; rp = rp->next,k+=17) {
  58.              if (Nr_sorttype)   
  59.             {  
  60.              strcpy(buf,rp->alias) ;
  61.              /* remove trailing spaces */
  62.              if((cp = strchr(buf,' ')) == NULLCHAR)
  63.                 cp = &buf[strlen(buf)] ;
  64.              if(cp != buf)           /* don't include colon for null alias */
  65.                 *cp++ = ':' ;
  66.              pax25(cp,rp->call) ;
  67.                
  68.             } 
  69.               else 
  70.              {
  71.               pax25(buf,rp->call);
  72.               cp=&buf[strlen(buf)];
  73.               *cp++=':';
  74.               strcpy(cp,rp->alias);
  75.              }
  76.             sprintf(&temp[k],"%-16s",buf);
  77.             }
  78.  
  79.          qsort(temp,(size_t)j,17,strcmp);
  80.         
  81.          for (i=0,k=0;i<j;i++,k+=17) {       
  82.             tprintf("%-16s  ",&temp[k]) ;
  83.             if(column++ == 4) {
  84.                 if(tprintf("\n") == EOF)
  85.                        { 
  86.                     free(temp);
  87.                     return 0;
  88.                        }
  89.                 column = 1 ;
  90.             }
  91.         }
  92.  
  93.      if(column != 1)
  94.         tprintf("\n") ;
  95.      free(temp);        
  96.     } 
  97.     return 0 ;
  98. }
  99.  
  100. /* netrom Route Dump Sort - ALIAS or CALL first */
  101. /* Add this function in nrcmd.c                 */
  102.  
  103. static
  104. doroutesort(argc,argv,p)
  105. int argc ;
  106. char *argv[] ;
  107. void *p ;
  108. {
  109.     extern unsigned Nr_sorttype;
  110.  
  111.     if(argc < 2) {
  112.         tprintf("Netrom Sort by %s\n", Nr_sorttype ? "Alias" : "Call" ) ;
  113.         return 0 ;
  114.     }
  115.     
  116.     switch(argv[1][0]) {
  117.         case 'A':
  118.         case 'a':
  119.             Nr_sorttype = 1 ;
  120.             break ;
  121.         case 'C':
  122.         case 'c':
  123.             Nr_sorttype = 0 ;
  124.             break ;
  125.         default:
  126.             tprintf("usage: netrom sort [alias|call]\n") ;
  127.             return -1 ;
  128.     }
  129.  
  130.     return 0 ;
  131. }
  132.  
  133.